/**
 * @class 用户数据代理
 * @author DuskyHuang 圣子
*/

import { Proxy, decorators } from 'cfw';
import { LocalStorageKeys, LANGUAGES } from 'const';
const { singleton } = decorators;

@singleton
export class UserProxy extends Proxy {

    declare public static readonly instance: UserProxy;
    private constructor() { super(); }

    public get guided(): boolean {
        return localStorage.getItem(GUIDED) === 'guided';
    }

    public get language(): language {
        const value = localStorage.getItem(LANG) as language;
        if (LANGUAGES.contains(value)) return value;
        else return null;
    }

    public updateGuided(): void {
        localStorage.setItem(GUIDED, 'guided');
    }

    public updateLanguage(lang: language): void {
        localStorage.setItem(LANG, lang);
    }
}

const { GUIDED, LANG } = LocalStorageKeys;

export const user = UserProxy.instance;